//
//  LSMyPuerseVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/8/10.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "LSMyPuerseVC.h"
#import "LSRechargeVC.h"
#import "LSCashVC.h"
#import "LSPuerseDetailVC.h"
#import "LSPuerseDescriptionVC.h"

@interface LSMyPuerseVC ()
@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;
@property (weak, nonatomic) IBOutlet UIButton *payCheckBtn;
@property (weak, nonatomic) IBOutlet UIButton *takeMoneyBtn;
@property (weak, nonatomic) IBOutlet UIButton *detailBtn;

@end

@implementation LSMyPuerseVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    [self sendRequest];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"我的钱包";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    self.payCheckBtn.layer.masksToBounds = YES;
    self.payCheckBtn.layer.cornerRadius = 5.0f;
    
    self.takeMoneyBtn.layer.masksToBounds = YES;
    self.takeMoneyBtn.layer.cornerRadius = 5.0f;
    
    self.detailBtn.layer.masksToBounds = YES;
    self.detailBtn.layer.cornerRadius = 5.0f;
    
    [self sendRequest];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
//充值
- (IBAction)clickPayCheck:(UIButton *)sender {
    
    LSRechargeVC * LSRecharge = [[LSRechargeVC alloc]init];
    [self.navigationController pushViewController:LSRecharge animated:YES];
    
}

//提现
- (IBAction)clickTakeMoney:(UIButton *)sender {
    LSCashVC * LSCash = [[LSCashVC alloc]init];
    LSCash.cashStr = self.balanceLabel.text;
    [self.navigationController pushViewController:LSCash animated:YES];
}

//明细
- (IBAction)clickDetail:(UIButton *)sender {
    LSPuerseDetailVC * LSPuerseDetail = [[LSPuerseDetailVC alloc]init];
    [self.navigationController pushViewController:LSPuerseDetail animated:YES];
    
}

//钱包功能说明
- (IBAction)puerseDetailBtn:(UIButton *)sender {
    LSPuerseDescriptionVC * LSPuerseDescription = [[LSPuerseDescriptionVC alloc]init];
    [self.navigationController pushViewController:LSPuerseDescription animated:YES];
    
}
#pragma mark - 请求数据
-(void)sendRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    dic[@"token"] = allConstMemberToken;
    dic[@"userId"] = allConstMemberid;


    [LSHttpTool sendHttpData:@"getUserBalance_app_pay.im.lensum" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        NSString * balanceStr = [YZBase64 textFromBase64String:dicInfo[@"data"][@"balance"]];
        self.balanceLabel.text = [NSString stringWithFormat:@"￥%.2f",[balanceStr floatValue]];
        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:@"网络连接错误"];
    }];

}
@end
